package com.dek.seckill.common.mq;


import com.dek.seckill.common.util.JsonUtil;
import com.dek.seckill.entity.GoodsMessage;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Service;

@Service
public class MQConsumer {


    @RabbitListener(queues = MQConfig.QUEUE)
    public void consume(String message) {
        System.out.println("consumer msg " + message);
    }

    @RabbitListener(queues = {MQConfig.TOPIC_QUEUE_1, MQConfig.TOPIC_QUEUE_2})
    public void consumeTopic(String message) {
        System.out.println("consumeTopic msg " + message);
    }

    @RabbitListener(queues = MQConfig.HEADER_QUEUE)
    public void consumeHeader(byte[] message) {
        System.out.println("consumeHeader msg " + message);
    }

    @RabbitListener(queues = MQConfig.SECKILL_QUEUE)
    public void consumeSeckill(String message) {
        GoodsMessage goodsMessage = JsonUtil.fromJson(message, GoodsMessage.class);
        String user = goodsMessage.getUser();
        String goodsId = goodsMessage.getGoodsId();
        // 下单
    }

}
